package com.vcredit.creditcat.service;

import java.util.List;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.vcredit.creditcat.model.RecommendCard;
import com.vcredit.creditcat.vo.RecommendCardVo;
import com.vcredit.creditcat.framework.pagination.Criteria;
import com.vcredit.creditcat.framework.pagination.Page;
import com.vcredit.creditcat.persistence.base.RecommendCardMapper;

 /*
  * @author zhangxingong
  * @version 1.0
  * @since 1.0
 */
@Service
public class RecommendCardService {
    
  @Autowired
	private RecommendCardMapper recommendCardMapper;
    
	public Page<RecommendCard> findByPage(Criteria criteria){
	    return new Page<RecommendCard>(recommendCardMapper.findByPageCount(criteria), recommendCardMapper.findByPage(criteria));
	}
	
	public List<RecommendCard> find(RecommendCard recommendCard){
	    return recommendCardMapper.find(recommendCard);
	}
	
	public RecommendCard findById(Long cardId){
	    return recommendCardMapper.findById(cardId);
	}
	
	public RecommendCard findAll(){
	    return recommendCardMapper.findAll();
	}
	
	public void save(RecommendCardVo recommendCardVo){
	  try {
	     RecommendCard recommendCard = new RecommendCard();
	     BeanUtils.copyProperties(recommendCard, recommendCardVo);
	     recommendCardMapper.insert(recommendCard);
       }catch (Exception e) {
           e.printStackTrace();
       }
	}
	
	public void update(RecommendCard recommendCard){
		recommendCardMapper.update(recommendCard);
	}
	
	public void removeRecommendCard(String ids){
	  for (String cardIdString : ids.split(",")) {
        Long cardId = Long.parseLong(cardIdString);
        recommendCardMapper.delete(cardId);
      }
	}
	
}
